package org.example.teachermanager.service;

import org.example.teachermanager.dao.TeacherRepository;
import org.example.teachermanager.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class TeacherService {
    @Autowired
    public TeacherRepository teacherRepository;

    public List<Teacher> findByNameLike(String name) {
        return teacherRepository.findByNameLike(name);
    }
    public Page<Teacher> findAll(Pageable pageable) {
        return teacherRepository.findAll(pageable);
    }

    public Optional<Teacher> findById(int id) {
        return teacherRepository.findById(id);
    }

    public Page<Teacher> findByNameLike(String name, Pageable pageable) {
        return teacherRepository.findByNameLike(name, pageable);
    }
    public Page<Teacher> findBySex(String sex, Pageable pageable) {
        return teacherRepository.findBySex(sex, pageable);
    }
    public Page<Teacher> findByNumber(String number, Pageable pageable) {
        return teacherRepository.findByNumber(number, pageable);
    }
    public void insert(Teacher teacher) {
        teacherRepository.save(teacher);
    }

    public void update(Teacher teacher) {
        teacherRepository.save(teacher);
    }

    public void delete(int id) {
        teacherRepository.deleteById(id);
    }
    public Teacher add(Teacher teacher) {
        return teacherRepository.save(teacher);
    }

}
